//% color="#48C0A3"
namespace Encoder {
    //% block="read switch 8:[PIN8] 4:[PIN4] 2:[PIN2] 1:[PIN1]" blockType="reporter"
    //% PIN8.shadow="dropdown" PIN8.options="PIN_8"
    //% PIN4.shadow="dropdown" PIN4.options="PIN_4"
    //% PIN2.shadow="dropdown" PIN2.options="PIN_2"
    //% PIN1.shadow="dropdown" PIN1.options="PIN_1"
    export function readSwitch(parameter: any, block: any) {
        let pin8 = parameter.PIN8.code;
        let pin4 = parameter.PIN4.code;
        let pin2 = parameter.PIN2.code;
        let pin1 = parameter.PIN1.code;
        Generator.addCode(`digitalRead(${pin8})*8+digitalRead(${pin4})*4+digitalRead(${pin2})*2+digitalRead(${pin1})`);
    }

   //% block="switch value[VALUE]" blockType="reporter"
   //% VALUE.shadow="dropdown" VALUE.options="VALUE"
    export function switchValue(parameter: any, block: any) {
        let value = parameter.VALUE.code;
        Generator.addCode(`${value}`);
    } 
}
